package com.navi.loaddata.core.util;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.apache.commons.dbutils.QueryRunner;

import java.beans.PropertyVetoException;

public class JdbcUtil {
    static ComboPooledDataSource dataSource_mes;
    static ComboPooledDataSource dataSource_wms;
    static ComboPooledDataSource dataSource_gp;
    static ComboPooledDataSource dataSource_gp_test;
    static ComboPooledDataSource dataSource_mes_user;
    static ComboPooledDataSource dataSource_mysql_test;
    static ComboPooledDataSource dataSource_mysql;
    static ComboPooledDataSource dataSource_ora_edaldr;
    static ComboPooledDataSource dataSource_ora_spc;

    static {
        try {
            //设置连接池大小
            dataSource_mes = new ComboPooledDataSource();
            dataSource_mes.setInitialPoolSize(20);
            dataSource_mes.setMinPoolSize(10);
            dataSource_mes.setMaxPoolSize(50);

            dataSource_mes.setUser("p1rptadm");
            dataSource_mes.setPassword("adm1300");
            dataSource_mes.setDriverClass("oracle.jdbc.driver.OracleDriver");
            dataSource_mes.setJdbcUrl("jdbc:oracle:thin:@//10.50.10.15:1521/edbdb");

        } catch (PropertyVetoException e) {
            e.printStackTrace();
        }

        try {
            dataSource_wms = new ComboPooledDataSource();
            dataSource_wms.setInitialPoolSize(20);
            dataSource_wms.setMinPoolSize(10);
            dataSource_wms.setMaxPoolSize(50);

            dataSource_wms.setUser("CHOTWMS");
            dataSource_wms.setPassword("JT-chot-wms2018");
            dataSource_wms.setDriverClass("oracle.jdbc.driver.OracleDriver");
            dataSource_wms.setJdbcUrl("jdbc:oracle:thin:@//10.56.200.98:1521/WMS");

        } catch (PropertyVetoException e) {
            e.printStackTrace();
        }

        try {
            dataSource_gp = new ComboPooledDataSource();
            dataSource_gp.setInitialPoolSize(3);
            dataSource_gp.setMinPoolSize(2);
            dataSource_gp.setMaxPoolSize(5);

            dataSource_gp.setUser("rptetl");
            dataSource_gp.setPassword("rptetl");

            dataSource_gp.setDriverClass("org.postgresql.Driver");
            dataSource_gp.setJdbcUrl("jdbc:postgresql://10.50.10.161:5432/qmsprd");
        } catch (PropertyVetoException e) {
            e.printStackTrace();
        }

        try {
            dataSource_gp_test = new ComboPooledDataSource();
            dataSource_gp_test.setInitialPoolSize(3);
            dataSource_gp_test.setMinPoolSize(2);
            dataSource_gp_test.setMaxPoolSize(5);

            dataSource_gp_test.setUser("sys");
            dataSource_gp_test.setPassword("sysadmin");
            dataSource_gp_test.setDriverClass("org.postgresql.Driver");
            dataSource_gp_test.setJdbcUrl("jdbc:postgresql://10.50.10.163:5432/qmstst");
        } catch (PropertyVetoException e) {
            e.printStackTrace();
        }

        try {
            //设置连接池大小
            dataSource_mes_user = new ComboPooledDataSource();
            dataSource_mes_user.setInitialPoolSize(3);
            dataSource_mes_user.setMinPoolSize(2);
            dataSource_mes_user.setMaxPoolSize(5);

            dataSource_mes_user.setUser("P1MESUSER");
            dataSource_mes_user.setPassword("mesuser");
            dataSource_mes_user.setDriverClass("oracle.jdbc.driver.OracleDriver");
            dataSource_mes_user.setJdbcUrl("jdbc:oracle:thin:@//10.50.10.5:1521/P1MESDB");

        } catch (PropertyVetoException e) {
            e.printStackTrace();
        }

        try {
            //设置连接池大小
            dataSource_mysql_test = new ComboPooledDataSource();
            dataSource_mysql_test.setInitialPoolSize(3);
            dataSource_mysql_test.setMinPoolSize(2);
            dataSource_mysql_test.setMaxPoolSize(5);

            dataSource_mysql_test.setUser("root");
            dataSource_mysql_test.setPassword("chot123");
            dataSource_mysql_test.setDriverClass("com.mysql.jdbc.Driver");
            dataSource_mysql_test.setJdbcUrl("jdbc:mysql://10.50.10.163:3306/ch_qms?characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true");

        } catch (PropertyVetoException e) {
            e.printStackTrace();
        }

        try {
            //设置连接池大小
            dataSource_mysql = new ComboPooledDataSource();
            dataSource_mysql.setInitialPoolSize(3);
            dataSource_mysql.setMinPoolSize(2);
            dataSource_mysql.setMaxPoolSize(5);

            dataSource_mysql.setUser("root");
            dataSource_mysql.setPassword("chot123");
            dataSource_mysql.setDriverClass("com.mysql.jdbc.Driver");
            dataSource_mysql.setJdbcUrl("jdbc:mysql://10.50.10.161:3306/ch_qms?characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true");

        } catch (PropertyVetoException e) {
            e.printStackTrace();
        }

        try {
            //设置连接池大小
            dataSource_ora_edaldr = new ComboPooledDataSource();
            dataSource_ora_edaldr.setInitialPoolSize(20);
            dataSource_ora_edaldr.setMinPoolSize(10);
            dataSource_ora_edaldr.setMaxPoolSize(50);

            dataSource_ora_edaldr.setUser("edaldr");
            dataSource_ora_edaldr.setPassword("edaldr");
            dataSource_ora_edaldr.setDriverClass("oracle.jdbc.driver.OracleDriver");
            dataSource_ora_edaldr.setJdbcUrl("jdbc:oracle:thin:@//10.56.200.107:1521/edadbt");

        } catch (PropertyVetoException e) {
            e.printStackTrace();
        }


        try {
            //设置连接池大小
            dataSource_ora_spc = new ComboPooledDataSource();
            dataSource_ora_spc.setInitialPoolSize(20);
            dataSource_ora_spc.setMinPoolSize(10);
            dataSource_ora_spc.setMaxPoolSize(50);

            dataSource_ora_spc.setUser("p1spcadm");
            dataSource_ora_spc.setPassword("adm1200");
            dataSource_ora_spc.setDriverClass("oracle.jdbc.driver.OracleDriver");
            dataSource_ora_spc.setJdbcUrl("jdbc:oracle:thin:@//10.50.10.10:1521/p1spcdb");

        } catch (PropertyVetoException e) {
            e.printStackTrace();
        }
    }

    public static QueryRunner getQueryRunner_mes() {
        QueryRunner queryRunner = new QueryRunner(dataSource_mes);
        return queryRunner;
    }

    public static QueryRunner getQueryRunner_wms() {
        QueryRunner queryRunner = new QueryRunner(dataSource_wms);
        return queryRunner;
    }

    public static QueryRunner getQueryRunner_gp() {
        QueryRunner queryRunner = new QueryRunner(dataSource_gp);
        return queryRunner;
    }
    public static QueryRunner getQueryRunner_gp_test() {
        QueryRunner queryRunner = new QueryRunner(dataSource_gp_test);
        return queryRunner;
    }

    public static QueryRunner getQueryRunner_mes_user() {
        QueryRunner queryRunner = new QueryRunner(dataSource_mes_user);
        return queryRunner;
    }

    public static QueryRunner getQueryRunner_mysql_test() {
        QueryRunner queryRunner = new QueryRunner(dataSource_mysql_test);
        return queryRunner;
    }

    public static QueryRunner getQueryRunner_mysql() {
        QueryRunner queryRunner = new QueryRunner(dataSource_mysql);
        return queryRunner;
    }

    public static QueryRunner getQueryRunner_ora_edaldr() {
        QueryRunner queryRunner = new QueryRunner(dataSource_ora_edaldr);
        return queryRunner;
    }

    public static QueryRunner getQueryRunner_ora_spc() {
        QueryRunner queryRunner = new QueryRunner(dataSource_ora_spc);
        return queryRunner;
    }

}
